//
//  ViewOfAdd.m
//  王宇先_10
//
//  Created by wyx on 16/3/22.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "ViewOfAdd.h"

@interface ViewOfAdd ()<UITextFieldDelegate>
@property (nonatomic, retain) UITextField *textName;
@property (nonatomic, retain) UITextField *textPhone;
@property (nonatomic, retain) UIButton *buttonOfSave;
@end

@implementation ViewOfAdd

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"添加联系人";
    [self createTextFiled];
    [self createButtonOfSave];
    
}
/** 创建 textfiled */
-(void)createTextFiled{
    //姓名
    self.textName = [[UITextField alloc] initWithFrame:CGRectMake(100, 200, 200, 50)];
    self.textName.placeholder = @"请输入姓名";
    self.textName.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:self.textName];
    [_textName release];
    self.textName.delegate = self;
    //电话
    self.textPhone = [[UITextField alloc] initWithFrame:CGRectMake(100, 300, 200, 50)];
    self.textPhone.placeholder = @"请输入电话";
    self.textPhone.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:self.textPhone];
    [_textPhone release];
    self.textPhone.delegate = self;
}
//点击空白处回收键盘
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesEnded:touches withEvent:event];
    [self.view endEditing:YES];
}
//点return 回收
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}
/** 创建保存 Button */
- (void)createButtonOfSave {
    self.buttonOfSave = [UIButton buttonWithType:UIButtonTypeSystem];
    self.buttonOfSave.frame = CGRectMake(180, 390, 40, 40);
    [self.buttonOfSave setTitle:@"Save" forState:UIControlStateNormal];
    self.buttonOfSave.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:self.buttonOfSave];
    [self.buttonOfSave release];
    [self.buttonOfSave addTarget:self action:@selector(saveAction:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)saveAction:(UIButton *)save{
    //执行协议方法
    [self.savedelegate AddContact:self.textName.text addNum:self.textPhone.text];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
